9f3ce915d5bc2adb6773dba73d6b7aece8efd263
4 * Created on July 6, 2007
6 * API for MediaWiki 1.8+
8 * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * http://www.gnu.org/copyleft/gpl.html
26 if (!defined('MEDIAWIKI')) {
27 // Eclipse helper - will be ignored in production
28 require_once ('ApiQueryBase.php');
32 * A query action to get image information and upload history.
36 class ApiQueryImageInfo
extends ApiQueryBase
{
38 public function __construct($query, $moduleName) {
39 parent
:: __construct($query, $moduleName, 'ii');
42 public function execute() {
43 $params = $this->extractRequestParams();
45 $history = $params['history'];
47 $prop = array_flip($params['prop']);
48 $fld_timestamp = isset($prop['timestamp']);
49 $fld_user = isset($prop['user']);
50 $fld_comment = isset($prop['comment']);
51 $fld_url = isset($prop['url']);
52 $fld_size = isset($prop['size']);
54 $pageIds = $this->getPageSet()->getAllTitlesByNamespace();
55 if (!empty($pageIds[NS_IMAGE
])) {
56 foreach ($pageIds[NS_IMAGE
] as $dbKey => $pageId) {
58 $title = Title
:: makeTitle(NS_IMAGE
, $dbKey);
59 $img = wfFindFile($title);
63 $data['missing'] = '';
66 $data['repository'] = $img->getRepoName();
69 while($line = $img->nextHistoryLine()) { // assignment
73 $vals['timestamp'] = wfTimestamp(TS_ISO_8601
, $line->img_timestamp
);
75 $vals['user'] = $line->img_user_text
;
80 $vals['size'] = intval($line->img_size
);
81 $vals['width'] = intval($line->img_width
);
82 $vals['height'] = intval($line->img_height
);
85 $vals['url'] = $isCur ?
$img->getURL() : $img->getArchiveUrl($line->oi_archive_name
);
87 $vals['comment'] = $line->img_description
;
91 if (!$history) // Stop after the first line.
100 $this->addPageSubItems($pageId, $data);
105 protected function getAllowedParams() {
108 ApiBase
:: PARAM_ISMULTI
=> true,
109 ApiBase
:: PARAM_DFLT
=> 'timestamp|user',
110 ApiBase
:: PARAM_TYPE
=> array (
122 protected function getParamDescription() {
124 'prop' => 'What image information to get.',
125 'history' => 'Include upload history',
129 protected function getDescription() {
131 'Returns image information and upload history'
135 protected function getExamples() {
137 'api.php?action=query&titles=Image:Albert%20Einstein%20Head.jpg&prop=imageinfo',
138 'api.php?action=query&titles=Image:Test.jpg&prop=imageinfo&iihistory&iiprop=timestamp|user|url',
142 public function getVersion() {
143 return __CLASS__
. ': $Id$';